/**
 * @copyright Copyright (c) 2025 
 * CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author xxxcsg
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "parameter.h"

#define DEVINFO_VERSION "1.0"
#define DEAMON_VERSION "1.0"
#define ETH_MESG_VERSION "1.0"
#define SIM_MESG_VERSION "1.1"
#define POWER_MESG_VERSION "1.1"
#define LOGIN_INFO_VERSION "1.0"
#define OTP_SERVER_VERSION "1.0"
static char *get_func_version(int func)
{
    char tmp[16] = {0};

    switch (func)
    {
    case HAWK_EYE_FUNC_DEVINFO:
        strcpy(tmp, DEVINFO_VERSION);
        break;
    case HAWK_EYE_FUNC_DEAMON:
        strcpy(tmp, DEAMON_VERSION);
        break;
    case HAWK_EYE_FUNC_ETH_MESG:
        strcpy(tmp, ETH_MESG_VERSION);
        break;
    case HAWK_EYE_FUNC_SIM_MESG:
        strcpy(tmp, SIM_MESG_VERSION);
        break;
    case HAWK_EYE_FUNC_POWER_MESG:
        strcpy(tmp, POWER_MESG_VERSION);
        break;
    case HAWK_EYE_FUNC_LOGIN_INFO:
        strcpy(tmp, LOGIN_INFO_VERSION);
        break;
    case HAWK_EYE_FUNC_OTP_SERVER:
        strcpy(tmp, OTP_SERVER_VERSION);
        break;
    default:
        break;
    }
    char *version = strdup(tmp);
    return version;
}
void printf_func_version(int func)
{
    const char *osName = GetOSFullName();
    const char *prefix = "PowerHarmony+ ";
    if (osName != NULL) {
        char str[128] = {0};
        char *funcVersion = NULL;
        size_t prefix_len = strlen(prefix);
        if (strncmp(osName, prefix, prefix_len) == 0) 
        {
            // 直接复制前缀之后的部分
            strcpy(str, osName + prefix_len);
            funcVersion = get_func_version(func);
            snprintf(str, sizeof(str), "%s.%s", osName + prefix_len,funcVersion);
            free(funcVersion);
        }
        
        printf("The version is [%s]\n", str);
    }
}